package com.example.esc_im_client.ui.friend;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.esc_im_client.R;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: CustomAdapter
 * @Description:
 * @Author: 墨渍
 * @Date: 2024/2/27 9:11
 **/
public class CustomAdapter extends ArrayAdapter<Object[]> {

    private Context mContext;
    private int mResource;

    private List<Object[]> mData;

    public CustomAdapter(@NonNull Context context, int resource, @NonNull List<Object[]> objects) {
        super(context, resource);
        mContext = context;
        mResource = resource;
        mData = objects;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(mResource, parent, false);
        }

        // 获取当前列表项的数据
        Object[] item = (Object[]) getItem(position);
        String itemName = (String) item[0];
        int itemImage = (int) item[1];

        // 获取列表项中的控件
        TextView textViewTitle = convertView.findViewById(R.id.textview_title);
        ImageView imageViewIcon = convertView.findViewById(R.id.imageview_icon);

        // 将数据设置到控件中
        textViewTitle.setText(itemName);
        imageViewIcon.setImageResource(itemImage);

        return convertView;
    }

//    @Override
//    public void add(@Nullable Object[] object) {
//        mData.add(object);
//        notifyDataSetChanged();
//    }
}
